package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import bot.AutoEdit;
import bot.City;
import bot.Util;

public class FullAutoButton extends JButton{
	/**
	 * Default Serialization
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * Text field that contains the url of the page being edited.
	 */
	private JTextField url;
	/**
	 * Text field that contains the date of access for the page.
	 */
	private JTextField date;
	/**
	 * The code for the Wikipedia page that is being edited
	 */
	private JTextArea code;
	
	public FullAutoButton(JTextField textCity, JTextField textDate, JTextArea wikiCode){
		super("Full Auto Test");
		url = textCity;
		date = textDate;
		code = wikiCode;
		
		addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg) {
				try{
					//make sure input is valid
					if (url.getText().equals("")){
						throw new IllegalArgumentException();
					}
					City choosen = new City(url.getText(), BotGui.data);
					//get the source code
					AutoEdit auto = new AutoEdit();
					auto.edit(url.getText(), choosen, date.getText(), code, true);
				}
				catch (IllegalArgumentException e){
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "Invaild city name");
				} 
			}
		});
	}
}
